import {getStorage, removeStorage, setStorage} from './localstoreage'
import {getSession} from './sessionStorage'
import {logout} from './toolkit'

// token
const TokenKey = 'LHToken'
export function getToken() {
  return getStorage(TokenKey)
}
export function setToken(token: string) {
  setStorage(TokenKey, token)
}
export function removeToken() {
  removeStorage(TokenKey)
}

// userId
const UserIdKey = 'userId'
export function getUserId(): string | null {
  const userId = getStorage(UserIdKey) as string | null
  return userId
}
export function setUserId(userId: string) {
  setStorage(UserIdKey, userId)
}
export function removeUserId() {
  removeStorage(UserIdKey)
}

// userRoles
const UserRolesKey = 'userRoles'
export function getUserRoles(): number[] | null {
  return Array.isArray(getStorage(UserRolesKey)) ? getStorage(UserRolesKey) : null
}
export function setUserRoles(userStatus: number[]) {
  setStorage(UserRolesKey, userStatus)
}
export function removeUserRoles() {
  removeStorage(UserRolesKey)
}

// userName
const UserNameKey = 'userName'
export function getUserName(): string | null {
  return getStorage(UserNameKey)
}
export function setUserName(userName: string) {
  // return Cookies.set(UserNameKey, userName, cookiesOption);
  setStorage(UserNameKey, userName)
}
export function removeUserName() {
  removeStorage(UserNameKey)
}

// userPass
const UserPassKey = 'userPass'
export function getUserPass(): string | null {
  return getStorage(UserPassKey)
}
export function setUserPass(userPass: string) {
  setStorage(UserPassKey, userPass)
}
export function removeUserPass() {
  removeStorage(UserPassKey)
}

// userStatus
export type UserStatus = {login: boolean}
const UserStatusKey = 'userStatus'
export function getUserStatus(): UserStatus {
  const userStatus = getStorage(UserStatusKey)
  return userStatus === null ? {login: false} : userStatus
}
export function setUserStatus(stastus: UserStatus) {
  setStorage(UserStatusKey, stastus)
}
export function removeUserStatus() {
  removeStorage(UserStatusKey)
}
